package com.mxm.mall.demo;

import com.mxm.mall.demo.entity.FullReduction;
import com.mxm.mall.demo.entity.Product;
import com.mxm.mall.demo.entity.ShoopingCar;
import com.mxm.mall.demo.math.ProductMath;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {
    public static void main(String[] args) {

        Map<Integer, Product> productMap = new HashMap<Integer, Product>();
        Product p1 = new Product(1, "苹果", new BigDecimal(8), new BigDecimal("1"));
        Product p2 = new Product(2, "草莓", new BigDecimal(13), new BigDecimal("1"));
        Product p3 = new Product(3, "芒果", new BigDecimal(20), new BigDecimal("1"));
        productMap.put(p1.getId(), p1);
        productMap.put(p2.getId(), p2);

        // Q1
        List<ShoopingCar> shoopingCars = new ArrayList<>();
        shoopingCars.add(new ShoopingCar(1, new BigDecimal(5)));
        shoopingCars.add(new ShoopingCar(2, new BigDecimal(34)));
        BigDecimal match = ProductMath.match(shoopingCars, productMap, null);
        System.out.println("Q1:" + match);

        //Q2
        productMap.put(p3.getId(), p3);
        shoopingCars.add(new ShoopingCar(3, new BigDecimal(5)));
        match = ProductMath.match(shoopingCars, productMap, null);
        System.out.println("Q2:" + match);

        //Q3
        p2.setDiscount(new BigDecimal("0.8")); //设置草莓为8折
        match = ProductMath.match(shoopingCars, productMap, null);
        System.out.println("Q3:" + match);

        //Q4
        match = ProductMath.match(shoopingCars, productMap, new FullReduction(new BigDecimal(100), new BigDecimal(10)));//增加满减
        System.out.println("Q4:" + match);
    }
}